//
// Created by xili on 2024/10/8 14:42.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int maximumSum(vector<int> &nums) {
        unordered_map<int, int> ump;
        int ans = -1;
        for (auto &it: nums) {
            int t = f(it);
            if (ump.count(t)) {
                ans = max(ans, it + ump[t]);
                ump[t] = max(ump[t], it);
            } else {
                ump[t] = it;
            }
        }
        return ans;
    }

    int f(int v) {
        int res = 0;
        while (v) {
            res += v % 10;
            v /= 10;
        }
        return res;
    }
};